//
//  LPEntity.m
//  SXH
//
//  Created by 房 国生 on 15/7/1.
//  Copyright (c) 2015年 lyss. All rights reserved.
//

#import "LPEntity.h"

@implementation LPEntity

- (instancetype)initWithAttributes:(NSDictionary *)attributes
{
    self = [super init];
    if (!self) {
        return nil;
    }
    
    self.storeID= [attributes valueForKeyPath:@"store_id"];
    self.store_name = [attributes valueForKeyPath:@"store_name"];
    self.store_phone = [attributes valueForKeyPath:@"store_phone"];
    
    NSArray *array  = [attributes valueForKeyPath:@"product_list"];
    if([array count] == 0){
        self.ID= [attributes valueForKeyPath:@"id"];
        self.title = [attributes valueForKeyPath:@"title"];
        self.content = [attributes valueForKeyPath:@"content"];
        self.album = [attributes valueForKeyPath:@"album"];
        self.album_thumb = [attributes valueForKeyPath:@"album_thumb"];
        self.star = [attributes valueForKeyPath:@"star"];
        self.price = [attributes valueForKeyPath:@"price"];
        self.old_price = [attributes valueForKeyPath:@"old_price"];
        self.ship_cost = [attributes valueForKeyPath:@"ship_cost"];
        self.sale_count = [attributes valueForKeyPath:@"sale_count"];
        self.address = [attributes valueForKeyPath:@"address"];
        self.product_introduce = [NSString stringWithFormat:@"%@%@", IMAGE_URL,[attributes valueForKeyPath:@"product_introduce"]];
        self.product_attr = [NSString stringWithFormat:@"%@%@", IMAGE_URL,[attributes valueForKeyPath:@"product_attr"]];
        self.comment_list = [NSString stringWithFormat:@"%@%@", IMAGE_URL,[attributes valueForKeyPath:@"comment_list"]];
        self.product_class_id = [attributes valueForKeyPath:@"product_class_id"];
    }else{
        for (NSDictionary* attributes in array) {
            self.ID= [attributes valueForKeyPath:@"id"];
            self.title = [attributes valueForKeyPath:@"title"];
            self.content = [attributes valueForKeyPath:@"content"];
            self.album = [attributes valueForKeyPath:@"album"];
            self.album_thumb = [attributes valueForKeyPath:@"album_thumb"];
            self.star = [attributes valueForKeyPath:@"star"];
            self.price = [attributes valueForKeyPath:@"price"];
            self.old_price = [attributes valueForKeyPath:@"old_price"];
            self.ship_cost = [attributes valueForKeyPath:@"ship_cost"];
            self.sale_count = [attributes valueForKeyPath:@"sale_count"];
            self.address = [attributes valueForKeyPath:@"address"];
            self.product_introduce = [NSString stringWithFormat:@"%@%@", IMAGE_URL,[attributes valueForKeyPath:@"product_introduce"]];
            self.product_attr = [NSString stringWithFormat:@"%@%@", IMAGE_URL,[attributes valueForKeyPath:@"product_attr"]];
            self.comment_list = [NSString stringWithFormat:@"%@%@", IMAGE_URL,[attributes valueForKeyPath:@"comment_list"]];
            self.product_class_id = [attributes valueForKeyPath:@"product_class_id"];
            self.can_sale = [attributes valueForKey:@"can_sale"];
        }
    }
    return self;
}

- (instancetype)initListWithAttributes:(NSDictionary *)attributes
{
    self = [super init];
    if (!self) {
        return nil;
    }
    
    self.ID= [attributes valueForKeyPath:@"id"];
    self.title = [attributes valueForKeyPath:@"title"];
    self.content = [attributes valueForKeyPath:@"content"];
    self.album = [attributes valueForKeyPath:@"album"];
    self.album_thumb = [attributes valueForKeyPath:@"album_thumb"];
    self.star = [attributes valueForKeyPath:@"star"];
    self.price = [attributes valueForKeyPath:@"price"];
    self.old_price = [attributes valueForKeyPath:@"old_price"];
    self.ship_cost = [attributes valueForKeyPath:@"ship_cost"];
    self.sale_count = [attributes valueForKeyPath:@"sale_count"];
    self.address = [attributes valueForKeyPath:@"address"];
    self.product_introduce = [NSString stringWithFormat:@"%@%@", IMAGE_URL,[attributes valueForKeyPath:@"product_introduce"]];
    self.product_attr = [NSString stringWithFormat:@"%@%@", IMAGE_URL,[attributes valueForKeyPath:@"product_attr"]];
    self.comment_list = [NSString stringWithFormat:@"%@%@", IMAGE_URL,[attributes valueForKeyPath:@"comment_list"]];
    self.product_class_id = [attributes valueForKeyPath:@"product_class_id"];
    self.can_sale = [attributes valueForKey:@"can_sale"];

    return self;
}

@end
